#ifndef _DXYLOCKLIST_H_
#define _DXYLOCKLIST_H_

#include <list>
#include <mutex>

namespace dxy
{

template<class T>
class DxyLockList
{
public:
    void push_back(T && t);
    T front();
    void pop_front();
    T frontAndPop();
    size_t size();

private:
    std::list<T>        m_list;
    std::mutex          m_mutex;
};

template<class T>
void DxyLockList<T>::push_back(T && t)
{
    std::unique_lock<std::mutex> lk(m_mutex);
    m_list.push_back(std::forward<T>(t));
}

template<class T>
T DxyLockList<T>::front()
{
    std::unique_lock<std::mutex> lk(m_mutex);
    return m_list.front();
}

template<class T>
T DxyLockList<T>::frontAndPop()
{
    // std::cout << "pop" << std::endl;
    std::unique_lock<std::mutex> lk(m_mutex);
    auto t = m_list.front();
    m_list.pop_front();
    return t;
}

template<class T>
void DxyLockList<T>::pop_front()
{
    std::unique_lock<std::mutex> lk(m_mutex);
    m_list.pop_front();
}

template<class T>
size_t DxyLockList<T>::size()
{
    std::unique_lock<std::mutex> lk(m_mutex);
    return m_list.size();
}


}


#endif